#pragma once
#include <string>
#include <vector>
#include "util/NonCopyable.h"

enum EMailSendResult{
    ESR_OK,
    ESR_UNKNOWN_ERROR,
    ESR_CONNECT_FAILED,
    ESR_SEND_EHLO_FAILED,
    ESR_RECV_EHLO_ACK_FAILED,
    ESR_RECV_EHLO_ERROR,
    ESR_AUTH_LOGIN_FAILED,
    ESR_RECV_AUTH_LOGIN_ACK_FAILED,
    ESR_RECV_AUTH_LOGIN_ERROR,
    ESR_INPUT_ACCOUNT_FAILED,
    ESR_RECV_INPUT_ACCOUNT_ACK_FAILED,
    ESR_RECV_INPUT_ACCOUNT_ERROR,
    ESR_INPUT_PSWD_FAILED,
    ESR_RECV_INPUT_PSWD_ACK_FAILED,
    ESR_RECV_INPUT_PSWD_ERROR,
    ESR_INPUT_MAIL_FROM_FAILED,
    ESR_RECV_INPUT_MAIL_FROM_ACK_FAILED,
    ESR_RECV_INPUT_MAIL_FROM_ERROR,
    ESR_INPUT_RCPT_TO_FAILED,
    ESR_RECV_INPUT_RCPT_TO_ACK_FAILED,
    ESR_RECV_INPUT_RCPT_TO_ERROR,
    ESR_INPUT_DATA_FAILED,
    ESR_RECV_INPUT_DATA_ACK_FAILED,
    ESR_RECV_INPUT_DATA_ERROR,
    ESR_SEND_EMAIL_HEAD_FAILED,
    ESR_SEND_EMAIL_CONTENT_FAILED,
    ESR_SEND_EMAIL_ATTACH_HEAD_FAILED,
    ESR_READ_ATTACH_FILE_FAILED,
    ESR_SEND_EMAIL_ATTACH_CONTENT_FAILED,
    ESR_INPUT_FIN_FAILED,
    ESR_RECV_INPUT_FIN_ACK_FAILED,
    ESR_RECV_INPUT_FIN_ERROR,
    ESR_INPUT_QUIT_FAILED,
    ESR_RECV_INPUT_QUIT_ACK_FAILED,
    ESR_RECV_INPUT_QUIT_ERROR
};

/**
 * @brief The CSimpleMailSender class
 * 这是一个简易的邮件发送类，使用方法如下:
 * <pre>
 * CSimpleMailSender c(
 *     "smtp.163.com",
 *     25,
 *     "from_whom@qq.com",
 *     "to_whom@163.com",
 *     "this is a test title",
 *     "This is mail content");
 * c.SendMail();
 * </pre>
 */
class CSimpleMailSender
        : public qcutil::NonCopyable
{
public:
    CSimpleMailSender(const std::string& server_domain, // SMTP服务器域名
                      unsigned short server_port,       // SMTP服务器端口
                      const std::string& user_name, // 用户名,xxx@yyy.com
                      const std::string& password,  // 密码
                      const std::string& mail_send_to, // 发送给谁，zzz@yyy.com。存在多个时用空格或TAB分割。
                      const std::string& email_title, // 邮件标题
                      const std::string& email_content // 邮件内容
                      );
    ~CSimpleMailSender();
public:
    // 增加邮件附件。
    void add_mail_attachment(const std::string& file_path);
    // 发送出去
    EMailSendResult send_mail();
private:
    std::string m_server_domain;
    unsigned short m_server_port;
    std::string m_user_name;
    std::string m_password;
    std::string m_mail_send_to;
    std::string m_email_title;
    std::string m_email_content;
    std::vector<std::string> m_email_attachments;
};
